package com.archermind.boc.socket.handler;

import java.util.HashMap;

import org.apache.mina.core.session.IoSession;

import com.archermind.boc.Logger;
import com.archermind.boc.utils.UtilsTools;

public class CacheSession {

	private final static Logger logger = Logger.getLogger(CacheSession.class.getName());

	private static HashMap<Long, IoSession> sessionMap = new HashMap<Long, IoSession>();

	private static HashMap<Long, String> sessionIDMap = new HashMap<Long, String>();

	public static void addSession(IoSession session) {
		sessionMap.put(session.getId(), session);
		sessionIDMap.put(session.getId(), UtilsTools.getSessionID(session));
		logger.info("[Add Cache] [" + sessionMap.size() + "]");
	}

	public static void removeSession(Long id) {
		sessionMap.remove(id);
		sessionIDMap.remove(id);
		logger.info("[Del Cache] [" + sessionMap.size() + "]");
	}

	public static boolean isExistSession(Long id) {
		return sessionMap.containsKey(id);
	}

	public static IoSession getSession(Long id) {
		return sessionMap.get(id);
	}

	public static String getSessionID(Long id) {
		return sessionIDMap.get(id);
	}
}
